package com.example.demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.demo.entity.oldpartsmanage;
import com.example.demo.service.OldpartsmanageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("old")
@CrossOrigin//允许跨域
@Api(tags= "返修件相关操作类",value = "返修件相关操作类")
public class Oldpartsmanage {
    @Resource
    OldpartsmanageService OldpartsmanageService;

    @PostMapping("/storage")
    @ApiOperation(value ="入库",notes= "okey，wtime（入库时间）和dtime（出库时间）不需要输入，向数据库添加返修件信息，成功返回‘入库成功，失败返回‘入库失败’’")
    public String Storage(@RequestBody oldpartsmanage oldpartsmanage)
    {
        return OldpartsmanageService.Storage(oldpartsmanage);
    }

    @PostMapping("/query")
    @ApiOperation(value ="查询",notes= "返回返修件所有信息")
    public List queryoldpartsmanage(@RequestBody oldpartsmanage oldpartsmanage)
    {
        return OldpartsmanageService.queryoldpartsmanage(oldpartsmanage);
    }

    @PostMapping("/outbound")
    @ApiOperation(value ="出库",notes= "只输入okey，成功则更新dtime返回‘出库成功’，失败返回‘出库失败’")
    public String Outbound(int okey)
    {
        return OldpartsmanageService.Outbound(okey);
    }

    @PostMapping("/update")
    @ApiOperation(value ="修改信息",notes= "修改除okey外返修件所有信息，okey不能修改只作为标识")
    public String update(@RequestBody oldpartsmanage oldpartsmanage)
    {
        return OldpartsmanageService.update(oldpartsmanage);
    }

    @PostMapping("/page")
    @ApiOperation(value = "分页显示返修件信息",notes = "输入页码和记录条数呈现第几页和每页记录条数")
    public List<oldpartsmanage> getlist(){
        Page<oldpartsmanage> page = new Page<>(1, 5);
        Page<oldpartsmanage> oldpartsmanagePage = OldpartsmanageService.page(page, null);
        return oldpartsmanagePage.getRecords();
    }
}
